import { createSlice,PayloadAction } from "@reduxjs/toolkit";

export type PageInfoType = {
    title: string
    desc?: string
    js?: string
    css?: string
    isPublished?: boolean
}

const INNIT_STATE: PageInfoType = {
    title: '',
    desc: '',
    js: '',
    css: '',
    isPublished: true
}

const pageInfoSlice = createSlice({
    name:'pageInfo',  // 这个名字要和index.ts里面的 // pageInfo: pageInfoReducer的pageInfo对应起来
    
    initialState: INNIT_STATE,
    reducers:{
        resetPageInfo:(state: PageInfoType,action: PayloadAction<PageInfoType>)=>{
            return action.payload
        },

        // 修改标题
        changePageTitle:(state:PageInfoType,action:PayloadAction<string>)=>{
            state.title = action.payload
        }
    }
})

export const { resetPageInfo,changePageTitle } = pageInfoSlice.actions

export default pageInfoSlice.reducer